﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class admin_Flow_BackManage_UpdateFlowStepManager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            IList<TarreOA.TarreOAModels.User> list = UserManager.FindAll();
            Flow_NewFlowStep nfs = Flow_NewFlowStep_Service.FindFlowStepById(Convert.ToInt32(Request.QueryString["fid"]));
            Label1.Text = "步骤"+nfs.Sort_id.ToString()+" - 编辑经办人员";
            string[] flowStepManagers = nfs.Prc_users.Split(',');
            foreach (TarreOA.TarreOAModels.User u in list)
            {
                int state = 0;
                foreach (string flowStepManager in flowStepManagers)
                {
                    if (u.LoginName == flowStepManager)
                    {
                        lbSellManager.Items.Add(new ListItem("[" + u.Section.SectionName + "]" + u.UserName, u.LoginName));
                        state = 1;
                        break;
                    }
                }
                if (state == 0)
                {
                    lbSellUser.Items.Add(new ListItem("[" + u.Section.SectionName + "]" + u.UserName, u.LoginName));
                }
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string[] flowStepManagerstrs = Request.Form.GetValues("lbSellManager");
        string flowStepManagerstr = "";
        if (flowStepManagerstrs != null)
        {
            foreach (string var in flowStepManagerstrs)
            {
                flowStepManagerstr += var + ",";
            }
        }
        Flow_NewFlowStep nfs = new Flow_NewFlowStep();
        nfs.NewFlowStep_id=Convert.ToInt32(Request.QueryString["fid"]);
        nfs.Prc_users = flowStepManagerstr;
        if (Flow_NewFlowStep_Service.UpdateFlowStepManager(nfs))
        {
            Response.Redirect("FlowStepList.aspx?id=" + Request.QueryString["id"]+"&pageIndex="+Request.QueryString["pageIndex"]);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(),"","alert('修改失败！请重试！')",true);
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        lbSellManager.Items.Clear();
        lbSellUser.Items.Clear();
        IList<TarreOA.TarreOAModels.User> list = UserManager.FindAll();
        Flow_NewFlowStep nfs = Flow_NewFlowStep_Service.FindFlowStepById(Convert.ToInt32(Request.QueryString["fid"]));
        string[] flowStepManagers = nfs.Prc_users.Split(',');
        if (ddlSelectType.SelectedValue == "0")
        {
            foreach (TarreOA.TarreOAModels.User u in list)
            {
                int state = 0;
                foreach (string flowStepManager in flowStepManagers)
                {
                    if (u.LoginName == flowStepManager)
                    {
                        lbSellManager.Items.Add(new ListItem("[" + u.Section.SectionName + "]" + u.UserName, u.LoginName));
                        state = 1;
                        break;
                    }
                }
                if (state == 0)
                {
                    lbSellUser.Items.Add(new ListItem("[" + u.Section.SectionName + "]" + u.UserName, u.LoginName));
                }
            }
        }
        else
        {
            foreach (TarreOA.TarreOAModels.User u in list)
            {
                int state = 0;
                foreach (string flowStepManager in flowStepManagers)
                {
                    if (u.LoginName == flowStepManager)
                    {
                        lbSellManager.Items.Add(new ListItem("[" + u.PopedomGroup.PopedomGroupName + "]" + u.UserName, u.LoginName));
                        state = 1;
                        break;
                    }
                }
                if (state == 0)
                {
                    lbSellUser.Items.Add(new ListItem("[" + u.PopedomGroup.PopedomGroupName + "]" + u.UserName, u.LoginName));
                }
            }
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("FlowStepList.aspx?id=" + Request.QueryString["id"] + "&pageIndex=" + Request.QueryString["pageIndex"]);
    }
}
